<?php
	session_start();
	//require("../DAO/GioHangDTO.php");
	class GioHangDTO
	{
		public $masp;
		public $soluong;
		public $dongia;
		public $donvitinh;
		public $tongtien;
	}
	if(isset($_REQUEST['masp'])&& isset($_REQUEST['type'])&& isset($_REQUEST['soluong']))
	{
		
		
		$masp=$_REQUEST['masp'];
		$type=$_REQUEST['type'];
		$soluong=$_REQUEST['soluong'];
		$dongia=$_REQUEST['dongia'];
		$donvitinh=$_REQUEST['donvitinh'];
		$soluongcon=$_REQUEST['soluongcon'];
		
		$cart=new GioHangDTO();
		$cart->masp=$masp;
		$cart->soluong=$soluong;
		$cart->dongia=$dongia;
		$cart->donvitinh=$donvitinh;
		$cart->tongtien=$dongia*$soluong;
		$flag=0;
	
		$array;
		if(isset($_SESSION['Cart'])&& $_SESSION['Cart']!=null)
		{
			$array=$_SESSION['Cart'];
			$n=count($array);
			if($n>0)
			{
				$i=0;
				foreach($array as $c)
				{
					if($c->masp==$cart->masp)
					{
						//if($c->soluong+$cart->soluong<=$soluongcon)
						//{
							$cart->soluong=$c->soluong+$cart->soluong;
							$cart->tongtien=$c->tongtien+$cart->soluong*$cart->dongia;
							$array[$i]=$cart;
							$flag=1;
							break;
						//}
						//else
						//{
						//	$flag=2;
						//	break;
						//}
					}
					$i=$i+1;
				}
				if($flag==0)
				{
					$array[$n]=$cart;
				}
				else
				{
					
				}
			}
			else
			{
				$array[0]=$cart;
			}
		}
		else
		{
			$array[0]=$cart;
		}
		$_SESSION['Cart']=$array;
		//if($flag==2)
		//	echo "false";
		//else
			echo "true";
		
	
	}
?>